package bit2;

import jdk.jshell.spi.ExecutionControl;

import java.util.Scanner;
class MyException extends Exception{
    public MyException(){
        super();
    }
    public MyException(String message){
        super(message);
    }
}
class UserException extends Exception{
    public UserException(String message){
        super(message);
    }
}
class PasswordException extends Exception{
    public PasswordException(String password){
        super(password);
    }
}
public class bitMain4 {
    public static String userName="admin";
    public static String password="123456789";
    public static void login(String user,String password)throws UserException,PasswordException{
        if(!bitMain4.userName.equals(user)){
            throw new UserException("用户名错误");
        }
        if (!bitMain4.password.equals(password)){
            throw new PasswordException("密码错误");
        }
        System.out.println("登录成功");
    }
    public static void main(String[] args) {
        try {
            Scanner in=new Scanner(System.in);
            System.out.println("请输入用户名：");
            String user=in.nextLine();
            System.out.println("请输入密码：");
            String password=in.nextLine();
            login(user,password);
        }
        catch (PasswordException e){
            e.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void func2() throws MyException{
        int a=10;
        if(a==10){
            throw new MyException("异常出错信息");
        }
    }
    public static void main2(String[] args) {
        try {
            func2();
        }
        catch (MyException e){
            e.printStackTrace();
        }
    }
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
    public static void func()throws RuntimeException,NullPointerException{
        int a=10;
        if(a==10){
            throw new RuntimeException("a==10");
        }
    }
    public static void main3(String[] args) {
        try {
            func();
        }
        catch (RuntimeException e){
            e.printStackTrace();
        }
    }
}
